package com.dgut.courses_selecting_sys.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.dgut.courses_selecting_sys.constants.RabbitMqKey;
import com.dgut.courses_selecting_sys.dto.MQUserCourseDto;
import com.dgut.courses_selecting_sys.entity.UserCourse;
import com.dgut.courses_selecting_sys.mapper.UserCourseMapper;
import com.dgut.courses_selecting_sys.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@RabbitListener(queuesToDeclare = @Queue(value = "TEST_MQ",durable = "true"))
public class TestCourseUserConsumer {

    @RabbitHandler
    public void receive(String message){

        MQUserCourseDto jsonObject = JSON.parseObject(message,MQUserCourseDto.class);
        UserCourse userCourse =new UserCourse();
        userCourse.setUserId(jsonObject.getUserId());
        userCourse.setCourseId(jsonObject.getCourseId());
        log.info("用户选课日志："+userCourse);
    }
}